<template>
  <a-modal title="操作" style="top: 20px;" :width="800" v-model="visible" :maskClosable="false" :confirmLoading="confirmLoading" @ok="handleSubmit">
    <a-form :form="form">
      <a-form-item style="display:none"><a-input v-decorator="['id']" /></a-form-item>
      <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="用户ID"><a-input placeholder="用户ID" v-decorator="['userId']" /></a-form-item>
      <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="用户ID"><a-input placeholder="用户ID" v-decorator="['updateBy']" /></a-form-item>
      <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="用户ID"><a-input placeholder="用户ID" v-decorator="['createBy']" /></a-form-item>
      <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="纬度"><a-input placeholder="纬度" v-decorator="['latitude']" /></a-form-item>
      <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="经度"><a-input placeholder="经度" v-decorator="['longitude']" /></a-form-item>
      <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="用户姓名"><a-input placeholder="用户姓名" v-decorator="['userName']" /></a-form-item>
      <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="用户类型">
        <a-select placeholder="请选择用户类型" v-decorator="['userType']" allowClear>
          <a-select-option v-for="(b, index) in userTypeList" :key="index" :value="b.dictValue">{{ b.dictLabel }}</a-select-option>
        </a-select>
      </a-form-item>
    </a-form>
  </a-modal>
</template>
<script>
import { saveSysSignDetail } from '@/api/signDetail';
import pick from 'lodash.pick';
export default {
  name: 'SignDetailModal',
  props: {
    userTypeList: {
      type: Array,
      required: true
    }
  },
  components: {},
  data() {
    return {
      visible: false,
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      confirmLoading: false,
      mdl: {},
      form: this.$form.createForm(this)
    };
  },
  beforeCreate() {},
  created() {},
  methods: {
    add() {
      this.form.resetFields();
      this.edit({ id: 0 });
    },
    edit(record) {
      this.mdl = Object.assign(record);
      this.visible = true;
      this.$nextTick(() => {
        this.form.setFieldsValue(
          pick(this.mdl, 'id', 'userId', 'updateBy', 'updateTime', 'createBy', 'createTime', 'signTime', 'latitude', 'longitude', 'status', 'userName', 'userType')
        );
      });
    },
    handleSubmit(e) {
      e.preventDefault();
      this.form.validateFields((err, values) => {
        if (!err) {
          console.log('Received values of form: ', values);
          this.confirmLoading = true;
          saveSysSignDetail(values)
            .then(res => {
              if (res.code === 0) {
                this.$message.success('保存成功');
                this.$emit('ok');
                this.visible = false;
              } else {
                this.$message.error(res.msg);
              }
            })
            .catch(() => {
              this.$message.error('系统错误，请稍后再试');
            })
            .finally(() => {
              this.confirmLoading = false;
            });
        }
      });
    }
  },
  watch: {
    /*
      'selectedRows': function (selectedRows) {
        this.needTotalList = this.needTotalList.map(item => {
          return {
            ...item,
            total: selectedRows.reduce( (sum, val) => {
              return sum + val[item.dataIndex]
            }, 0)
          }
        })
      }
      */
  }
};
</script>
